﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BestLifePOS_Core.Data.Core;
using System.Data.SqlClient;
using BestLifePOS_Core.DomainObjects;
using System.Data;
using BestLifePOS_Core.Exceptions.DataBase;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeGetAllProductListByItemID : BestLifeDataAction<List<Price_List>>
    {
        //Get All ProductList
         private string GvProid;

         public BestLifeGetAllProductListByItemID(string PProid)
        {
            GvProid = PProid;
        }

         public override List<Price_List> Body(SqlConnection PConn)
        {
            try//get all product By Id
            {
                List<Price_List> LvList = new List<Price_List>();


                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.GetPLDetailsbyproid";
                LvCommand.Parameters.Add(new SqlParameter("@Pro_ID", GvProid));

                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {

                    Price_List LvPLList = new Price_List();
                   LvPLList.PL_Id=LvReader.GetValue(0).ToString();
                     LvPLList.Pro_ID=LvReader.GetValue(1).ToString();
                     LvPLList.Pro_Price=Convert.ToDecimal(LvReader.GetValue(2).ToString());
                     LvPLList.Ret_Price = Convert.ToDecimal(LvReader.GetValue(3).ToString());
                     LvPLList.Pur_price = Convert.ToDecimal(LvReader.GetValue(4).ToString());
                     LvPLList.PV = Convert.ToDecimal(LvReader.GetValue(5).ToString());
                     LvPLList.BV = Convert.ToDecimal(LvReader.GetValue(6).ToString());
                     LvPLList.Exp_Date=DateTime.Parse(LvReader.GetValue(7).ToString());
                     LvPLList.User_Id=LvReader.GetValue(8).ToString();
                     LvPLList.Date_Create = DateTime.Parse(LvReader.GetValue(9).ToString());
                     LvPLList.User_Modify=LvReader.GetValue(10).ToString();
                     LvPLList.Date_Modify = DateTime.Parse(LvReader.GetValue(11).ToString());


                     LvList.Add(LvPLList);
                }
                return LvList;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
